<?php if ( ! defined('ABSPATH')) exit('restricted access');

unset($_GET['action']);
unset($_GET['subaction']);

$xpath = array_filter(array_merge(array('gender'=>'man','side'=>'front','part'=>'head'), (array) $_GET));

$settings = array();
$dbkey = 'wpnukes_symptom_checker_'.$xpath['gender'];

if(get_option($dbkey)) $settings[$xpath['gender']] = get_option($dbkey);
else exit(sprintf(__('The %s is not found in record', THEME_NAME), $xpath['gender']));

function get_keys($data)
{
	$return = array();

	foreach($data as $k=>$v)
		$return[texttoslug($k)] = $v;

	return $return;
}

$data = $settings;

foreach($xpath as $key)
{
	$nkey = texttoslug($key);
	$last_data = (isset($data[$nkey])) ? $data[$nkey] : array();	

	if(isset($data[$nkey])) $data = get_keys($data[$nkey]);
	else $data = array();
}

if(is_numeric(key($data))) exit(json_encode(array_combine(array_keys($data), array_values($last_data))));
elseif( ! empty($data)) exit(json_encode(array_combine(array_keys($data), array_keys($last_data))));
else exit(__('The part settings are missing in the records', THEME_NAME));